﻿/*
Digraph (library for building, traversal, comparison and saving of directed
graph).

Copyright (C) 2014 Dmitry Merzagitovich Arslanov

This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option) any
later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*/

// How to create read-only digraph.
namespace Sample2
{
    // Define digraph types.
    using Vertex = Digraph.Vertex<string, string>;
    using Arc = Digraph.Arc<string, string>;
    using Graph = Digraph.Set<string, string>;
    using Builder = Digraph.Builder<string, string>;

    /// <summary>
    /// Class for graph creation.
    /// </summary>
    public static class GraphGenerator
    {
        /// <summary>
        /// Method to create read-only digraph.
        /// </summary>
        /// <returns>Sample of read-only digraph.</returns>
        public static Graph GenerateGraph()
        {
            // Create digraph by means of builder.
            Builder builder = new Builder();
            Vertex vertex1 = builder.NewVertex("v1");
            Vertex vertex2 = builder.NewVertex("v2");
            Arc arc = builder.NewArc(vertex1, vertex2);
            // Then return only digraph.
            // Builder is unavailable outside of creation method.
            return builder.Digraph;
        }
    }

    public static class App
    {
        public static void Main()
        {
            // Generate digraph by means of generator above.
            Graph graph = GraphGenerator.GenerateGraph();
            // Here only methods for digraph traversal,
            // comparison and saving are available.
            // Generated digraph can't be modified because there is no builder.
        }
    }
}
